import java.io.*;
import java.util.Scanner;

public class Demo1 {
    private static String path = "D:/Test/test.txt";

    public static void main1(String[] args) throws IOException {
        OutputStream outputStream = new FileOutputStream("D:/Test/test.txt");
        outputStream.write('H');
        outputStream.write('e');
        outputStream.write('l');
        outputStream.write('l');
        outputStream.write('o');
        outputStream.flush();
    }

    public static void main2(String[] args) throws IOException {
        OutputStream outputStream = new FileOutputStream("D:/Test/test",true);
        byte[] b = new byte[]{'e','f','g'};
        outputStream.write(b);
    }

    public static void main3(String[] args) throws FileNotFoundException, UnsupportedEncodingException {
        OutputStream outputStream = new FileOutputStream("D:/Test/test.txt");
        OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream, "UTF-8");
        PrintWriter writer = new PrintWriter(outputStreamWriter);

        writer.println("我是第一行~");
        writer.println("我是第二行~");
        writer.println("我是第三行~");
        writer.flush();
    }

    public static void main4(String[] args) throws IOException {
        Reader reader = new FileReader(path);
        while(true){
            int n = reader.read();
            if(n == -1){
                break;
            }
            System.out.printf("%c", n);
        }
    }

    public static void main5(String[] args) throws IOException {
        Writer writer = new FileWriter(path);
        PrintWriter printWriter = new PrintWriter(writer);
        printWriter.println("我是猪");
        printWriter.println("我是猪");
        printWriter.println("我是猪");

        printWriter.flush();
    }

    public static void main(String[] args) {
        char ch = '我';
        System.out.printf("%c", ch);
    }
}
